package maitaole.controller;


import com.alibaba.fastjson.JSON;
import maitaole.annotion.Parame;
import maitaole.annotion.RequestMapping;
import maitaole.bean.Role;
import maitaole.result.ResultNew;
import maitaole.service.impl.RoleServiceImpl;

import javax.servlet.annotation.WebServlet;
import java.util.List;

/**
 * @Author 李杰
 * @Description 类的功能描述
 * @Date 2023/5/16
 */
@WebServlet("/RoleController/*")
public class RoleController extends BaseServlet {

    RoleServiceImpl roleService = new RoleServiceImpl();
    ResultNew resultNew = new ResultNew();
    /*
    查询所有的用户信息
     */
    @RequestMapping("/selectRole2")
    public String  selectRole2(){
        List<Role> roles = roleService.getRoles();
        if(roles!=null){
            ResultNew sccuess = resultNew.sccuess(roles);
            return JSON.toJSONString(sccuess);
        }else {
            ResultNew fail = resultNew.fail();
            return JSON.toJSONString(fail);
        }
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("/selectRolePage")
    public String selectRolePage(@Parame("pageNum") Integer pageNum,@Parame("pageSize") Integer pageSize){
        List<Role> roles = roleService.pageRoles(pageNum, pageSize);
        if(roles!=null){
            ResultNew sccuess = resultNew.sccuess(roles);
            return JSON.toJSONString(sccuess);
        }else {
            ResultNew fail = resultNew.fail();
            return JSON.toJSONString(fail);
        }
    }
    @RequestMapping("/addRoleAndMenu")
    public void addRoleAndMenu(@Parame("roleName") String roleName,@Parame("roleDesc") String  roleDesc,@Parame("menu1Id") String[] menu1Id,@Parame("menu2Id") String[] menu2Id){
        System.out.println(roleName);
        System.out.println(menu1Id);
        System.out.println(menu2Id);
    }

    public static void main(String[] args) {

        RoleController roleController = new RoleController();
        String s = roleController.selectRole2();

    }
}

